﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace DictPPC
{
    public class Dictionary
    {
        #region Attributes
        #endregion

        #region Properties
        #endregion

        #region Method

        public string Search(string key, string uri)
        {
            StreamReader read = new StreamReader(uri + ".idx", Encoding.UTF8);
            string result = "";

            key = key.ToLower();
            while (!read.EndOfStream)
            {
                string temp = read.ReadLine();
                char[] delim = { '\t' };
                string[] arrTemp = temp.Split(delim);
                if (arrTemp[0] == key)
                {
                    StreamReader readata = new StreamReader(uri + ".dat", Encoding.UTF8);
                    readata.BaseStream.Position = long.Parse(arrTemp[1]);     

                    while (!readata.EndOfStream && temp != "")
                    {
                        temp = readata.ReadLine();
                        result += temp;
                        result += "\r\n";
                    }  
                    readata.Close();
                    readata.Dispose();
                    break;
                }

            }
            read.Close();
            read.Dispose();

            return result;
        }
        #endregion
    }
}
